import request from '@/utils/request'
import type {
  SpuData,
  ReponseData,
  SPUResponseData,
  AllTrademark,
  SpuImgResponseData,
  SaleAttrReponseData,
  SaleAttrListResponseData,
  SkuData,
  SkuInfoData,
} from './type'
enum API {
  // 获取已有的SPU的数据
  SPU_URL = '/admin/product/',
  // 获取品牌的数据
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  // 获取SPU照片的数据
  IMAGEURL_URL = '/admin/product/spuImageList/',
  // 获取SPU下的销售属性接口地址
  SPUSALEATTE_URL = '/admin/product/spuSaleAttrList/',
  // 获取全部销售属性
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  // 添加SPU
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  // 更新SPU
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  // 追加一个新增的SKU地址
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  // 查看某一个已有的SPU下全部的售卖的商品
  SKUINFO_URL = '/admin/product/findBySpuId/',
  // 删除SPU
  REMOVESPU_URL = '/admin/product/deleteSpu/',
}
// 获取某个三级分类下已有的SPU数据
export const reqSPU = (
  pageNo: number,
  limit: number,
  category3Id: number | string,
) =>
  request.get<any, SPUResponseData>(
    API.SPU_URL + `${pageNo}/${limit}?category3Id=${category3Id}`,
  )

// 获取品牌的数据
export const reqAllTrademark = () =>
  request.get<any, AllTrademark>(API.ALLTRADEMARK_URL)
// 获取SPU图片的数据
export const reqSpuImageList = (spuId: number) =>
  request.get<any, SpuImgResponseData>(API.IMAGEURL_URL + spuId)
// 获取SPU下的销售属性的数据
export const reqSpuSaleAttrList = (spuId: number) =>
  request.get<any, SaleAttrReponseData>(API.SPUSALEATTE_URL + spuId)
// 获取全部销售属性的数据
export const reqAllSaleAttr = () =>
  request.get<any, SaleAttrListResponseData>(API.ALLSALEATTR_URL)
// 增加或修改一个新的SPU
export const reqAddOrUpdateSPU = (data: SpuData) => {
  if (data.id) {
    return request.post<any, ReponseData>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, ReponseData>(API.ADDSPU_URL, data)
  }
}
// 添加SKU的请求方法
export const reqAddSku = (data: SkuData) =>
  request.post<any, ReponseData>(API.ADDSKU_URL, data)
// 获取SKU数据
export const reqSkuList = (spuId: number | string) =>
  request.get<any, SkuInfoData>(API.SKUINFO_URL + spuId)
// 删除SPU
export const reqRemoveSpu = (spuId: number | string) =>
  request.delete<any, ReponseData>(API.REMOVESPU_URL + spuId)
